<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding">
        <div class=" rc-pannel ">
            <div class=" rc-pannel-header">
                <div class="rc-flex layui-form toolbar rc-flex-justify-between">
                    <div class=" rc-flex rc-flex-vertical-center ">

                    </div>
                    <div>
                        <a href="/admin/cnf/Site/add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="iconfont">&#xe60e;</i> 添加站点</a>

                    </div>
                </div>


            </div>


            <div class="rc-pannel-body layui-form rc-pagepadding">

                <table class="layui-table">
                    <colgroup>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col style="width: 240px;">

                    </colgroup>
                    <thead>
                        <tr>
                            <th>站点名称</th>
                            <th>站点域名</th>
                            <th>绑定组织架构</th>
                            <th>状态</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($sites as $site) {
                        ?>
                            <tr>
                                <td><?php echo $site->title; ?></td>
                                <td><?php echo $site->domain; ?></td>
                                <td></td>
                                <td>
                                    <input type="checkbox" name="status" <?php echo $site->status == 1 ? 'checked' : '' ?> title="开启|关闭" lay-skin="switch" value="<?php echo $site->id; ?>" autocomplete="off" lay-filter="changestatus">
                                </td>
                                <td>
                                    <div class="rc-opbar" style="width: 150px;margin-left:15px">
                                        <a class="info " href="/admin/cnf/Site/edit?id=<?php echo $site->id ?>"> <i class="iconfont">&#xe643;</i> 编辑</a>
                                        <a siteid="<?php echo $site->id ?>" class="info systemadmin" href="javascript:;"> <i class="iconfont">&#xe65d;</i> 站点超管</a>
                                    </div>
                                </td>
                            </tr>
                        <?php
                        } ?>

                    </tbody>
                </table>



            </div>
        </div>
    </div>
</div>
<script>
    layui.use(function() {

        var layer = layui.layer;
        var form = layui.form;
        $('.systemadmin').click(function() {

            var siteid = $(this).attr('siteid');
            layer.open({
                type: 2,
                offset: 'r',
                move: false,
                anim: 'slideLeft', // 从右往左
                area: ['800px', '100%'],
                shade: 0.1,
                title: '设置站点超级管理员',
                id: 'ID-demo-layer-direction-r',
                content: '/admin/cnf/Site/systemAdmin?siteid=' + siteid
            });

        });


        // checkbox 事件

        form.on('switch(changestatus)', function(data) {
            var elem = data.elem; // 获得 checkbox 原始 DOM 对象
            var checked = elem.checked; // 获得 checkbox 选中状态
            var value = elem.value; // 获得 checkbox 值
            var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象
            layer.msg('checked 状态: ' + elem.checked);


            $.ajax({
                url: '/admin/cnf/Site/setStatus?id=' + value, //请求路径
                type: "POST", //请求方式
                data: {
                    status: (elem.checked ? 1 : -1)
                }, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("设置成功", function() {
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });


        });


    });
</script>